﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameUtils;
using ThouShaltNotBrick.Logic.GeneralObjects;

namespace ThouShaltNotBrick.Logic.Helpers
{
    public static class BrickHelpers
    {
        #region Methods
        public static RectangleF GetBrickRectangle(BrickWithCurrentState pBrick)
        {
            // position of bottom left corner [m]
            float x = pBrick.Column * Constants.BRICK_WIDTH;
            float y = Constants.BRICKS_Y_OFFSET + pBrick.Row * Constants.BRICK_HEIGHT;
            return new RectangleF(x, y, Constants.BRICK_WIDTH, Constants.BRICK_HEIGHT);
        }

        public static bool IsBrickExisting(BrickWithCurrentState pBrick)
        {
            return pBrick != null && pBrick.GetCurrentBrickState() != null;
        }

        public static int GetCoordinateAsBrickRow(float pY)
        {
            if (Constants.BRICKS_Y_OFFSET <= pY && pY <= Constants.BRICKS_Y_OFFSET + Constants.BRICK_ROWS * Constants.BRICK_HEIGHT)
            {
                int row = (int)((pY - Constants.BRICKS_Y_OFFSET) / Constants.BRICK_HEIGHT);
                return MathUtils.GetLimitedInt(row, 0, Constants.BRICK_ROWS - 1);
            }
            else
            {
                return -1;
            }
        }

        public static int GetCoordinateAsBrickColumn(float pX)
        {
            if (0 <= pX && pX <= Constants.BRICK_COLUMNS * Constants.BRICK_WIDTH)
            {
                int column = (int)(pX / Constants.BRICK_WIDTH);
                return MathUtils.GetLimitedInt(column, 0, Constants.BRICK_COLUMNS - 1);
            }
            else
            {
                return -1;
            }
        }
        #endregion
    }
}